package org.example.cloudindex.web;

import javax.servlet.http.HttpServletRequest;

import org.example.cloudindex.web.fegin.OrderDo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RefreshScope
public class IndexDo {
    @RequestMapping("index")
    public String index(HttpServletRequest request) {

        return "index" + request.getServerPort();
    }

    @Autowired
    RestTemplate restTemplate;

    @RequestMapping("fromOrder")
    public String order(){
        return restTemplate.getForObject(
                "http://cloud-order/order", String.class);
    }

    @Autowired
    OrderDo orderDo;
    @RequestMapping("fromOrderWithFeign")
    public String fromOrderWithFeign() {
        return orderDo.order();
    }

    // 注入配置参数
    @Value("${feign.circuitbreaker.enabled}")
    String circuitbreaker;

    @RequestMapping("fce")
    String getCircuitbreaker(){
        return "feign.circuitbreaker.enabled ="
                + circuitbreaker;
    }

}
